<template>
  <div>
    <div class="personal-info-box">
      <div class="triangle"></div>
      <div class="jersey-number">{{ playerInfo.playerNum }}</div>
      <div class="player-name">{{ playerInfo.playerName }}</div>
      <div class="player-position">{{ playerInfo.position }}</div>
      <div class="player-basic-info">
        <div class="player-info-item">
          <div>出生日期:</div>
          <div>{{ playerInfo.birthday }}</div>
        </div>
        <div class="player-info-item">
          <div>身高(CM):</div>
          <div>{{ playerInfo.height }}</div>
        </div>
        <div class="player-info-item">
          <div>体重(KG):</div>
          <div>{{ playerInfo.weight }}</div>
        </div>
        <div class="player-info-item">
          <div>国籍:</div>
          <div class="player-country">
            <img class="national-flag" :src="playerInfo.countryLogo" alt="" />
            <span>{{ playerInfo.country }}</span>
          </div>
        </div>
        <div class="player-info-item">
          <div>俱乐部:</div>
          <div class="player-club">
            <img class="club-logo" :src="playerInfo.clubLogo" alt="" />
            <span>{{ playerInfo.club }}</span>
          </div>
        </div>
      </div>
      <div class="player-img">
        <img :src="playerInfo.playerImg" alt="" />
      </div>
      <div class="bottom-tab-bar">
        <div class="personal-info-el-tabs">
          <el-tabs v-model="activeName">
            <el-tab-pane label="个人信息" name="personalInfo" />
            <el-tab-pane label="排名" name="personalRank" />
            <el-tab-pane label="比赛表现" name="matchPerformance" />
          </el-tabs>
        </div>
        <!-- <div class="selector-season">
          <el-select
            v-model="season"
            @focus="setMinWidthEmpty"
            style="width:150px"
            placeholder="请选择赛季"
          >
            <el-option
              v-for="item in options"
              :key="item.season"
              :label="item.label"
              :value="item.season"
            >
            </el-option>
          </el-select>
        </div> -->
      </div>
    </div>
    <div>
      <PersonalInfo
        key="PersonalInfo"
        :season="season"
        :playerId="playerId"
        v-show="activeName === 'personalInfo'"
      />
      <personalRank
        key="personalRank"
        :playerId="playerId"
        :season="season"
        v-show="activeName === 'personalRank'"
      />
      <MatchPerformance
        key="MatchPerformance"
        :playerId="playerId"
        v-show="activeName === 'matchPerformance'"
      />
    </div>
  </div>
</template>

<script>
import axios from "axios";
import MyTransition from "../transition/MyTransition";
import PersonalInfo from "./personalInfo/PersonalInfo";
import personalRank from "./personalRank/personalRank";
import MatchPerformance from "./matchPerformance/MatchPerformance";
import mixin from "../../mixin/mixin";
export default {
  name: "SinglePlayer",
  mixins: [mixin],
  components: {
    MyTransition,
    PersonalInfo,
    personalRank,
    MatchPerformance,
  },
  data() {
    return {
      activeName: "personalInfo",
      playerId: null,
      season: "2019赛季",
      options: [
        {
          season: "2019赛季",
          label: "2019赛季",
        },
        {
          season: "2018赛季",
          label: "2018赛季",
        },
        {
          season: "2017赛季",
          label: "2017赛季",
        },
        {
          season: "2016赛季",
          label: "2016赛季",
        },
      ],
      playerInfo: {},
    };
  },
  watch: {
    season: {
      handler(seasonId) {
        this.getPlayerInfo(parseInt(seasonId), this.playerId);
      },
    },
  },
  methods: {
    async getPlayerInfo(seasonId, playerId) {
      const { data } = await axios.get(
        `http://8.141.159.127:3000/api/v1/players/playerInfor/${seasonId}/${playerId}`
      );
      this.playerInfo = data[0];
    },
  },
  beforeRouteEnter(to, from, next) {
    const { playerId } = to.params;
    console.log("beforeRouteEnter:", playerId);
    next((vm) => {
      vm.playerId = parseInt(playerId);
      vm.getPlayerInfo(2019, playerId);
      vm.$store.commit("changePlayerId", parseInt(playerId));
    });
  },
  beforeRouteUpdate(to, from, next) {
    const { playerId } = to.params;
    console.log("beforeRouteUpdate:", playerId);
    this.playerId = parseInt(playerId);
    this.getPlayerInfo(2019, playerId);
    this.activeName = "personalInfo";
    this.$store.commit("changePlayerId", parseInt(playerId));
    next();
  },
};
</script>

<style scoped>
.personal-info-box {
  position: relative;
  background-color: #f1f6f9;
  width: 1440px;
  height: 294px;
  margin: auto;
}

.triangle {
  border-style: solid;
  border-width: 29px;
  border-color: #65d6c1 transparent transparent #65d6c1;
  width: 0;
  height: 0;
}

.jersey-number {
  position: absolute;
  top: 0;
  left: 35%;
  text-align: center;
  font-size: 250px;
  font-weight: bold;
  width: 30%;
  height: 237px;
  line-height: 237px;
  color: rgba(158, 158, 158, 30);
  /*background-color: #B500FE;*/
}

.player-name {
  position: absolute;
  top: 32%;
  left: 35%;
  text-align: center;
  font-size: 40px;
  width: 30%;
  height: 70px;
  line-height: 70px;
  color: #16c79a;
  font-weight: bold;
  /*background-color: navy;*/
}

.player-position {
  position: absolute;
  top: 60%;
  left: 35%;
  text-align: center;
  font-size: 30px;
  width: 30%;
  height: 40px;
  line-height: 40px;
  font-weight: bold;
  /*background-color: #9a6e3a;*/
}

.player-basic-info {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: absolute;
  top: 5%;
  right: 2%;
  width: 240px;
  height: 220px;
  font-weight: bold;
  /*background-color: #990055;*/
}

.player-info-item {
  display: flex;
  justify-content: space-between;
  flex-direction: row;
  line-height: 30px;
  text-align: left;
  width: 100%;
  height: 30px;
  /*background-color: #9a6e3a;*/
}

.player-info-item > div:nth-child(1) {
  width: 80px;
  /*background-color: red;*/
}

.player-info-item > div:nth-child(2) {
  line-height: 30px;
  width: 140px;
  height: 30px;
  /*background-color: blue;*/
}

.player-country,
.player-club {
  display: flex;
}

.national-flag {
  width: 30px;
  height: 30px;
}

.club-logo {
  width: 30px;
  height: 30px;
}

.player-img {
  position: absolute;
  top: 28%;
  left: 1%;
  width: 250px;
  height: 250px;
  border-radius: 50%;
  z-index: 2;
  /*background-color: #9a6e3a;*/
  /*background-color: #d4d4d9;*/
  overflow: hidden;
}

.player-img > img {
  margin-top: 13px;
  width: 175px;
  height: 225px;
  /*border-radius: 50%;*/
}

.bottom-tab-bar {
  position: absolute;
  bottom: 0;
  text-align: center;
  font-size: 30px;
  width: 100%;
  height: 57px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #194568;
}
.selector-season /deep/ .el-input {
  width: 80%;
}
.selector-season /deep/ .el-input__inner {
  height: 30px;
}
.selector-season /deep/ .el-input__suffix {
  top: 6px;
}
.personal-info-el-tabs {
  /*font-size: 30px;*/
  margin-top: 5px;
  margin-left: 300px;
  /*margin-right: 25px;*/
}
.personal-info-el-tabs /deep/ .el-tabs__item {
  color: white;
  font-size: 20px;
  font-weight: bold;
}
.personal-info-el-tabs /deep/ .el-tabs__nav-wrap::after {
  height: 0;
}
.personal-info-el-tabs /deep/ .el-tabs__active-bar {
  height: 3px;
  background-color: #16c79a;
}
.personal-info-el-tabs /deep/ .el-tabs__item:hover {
  color: #16c79a;
}
.personal-info-el-tabs /deep/ .el-tabs__item.is-active {
  color: #16c79a;
}
</style>
